package com.kgc.java.javaoop.chapter06.c6project;
import java.util.Scanner;

public class Menus {
    Scanner scan = new Scanner(System.in);
    Function fun = new Function();
    Employee employee = null;
    boolean result = false;
    int eNo = 0;
    double money = 0;
    public void firstMenu(){
            System.out.println("请输入用户名:");
            String id = scan.next();
            System.out.println("请输入密  码:");
            String pwd = scan.next();
            result = fun.login(id,pwd);
            if (result){
                System.out.println("登陆成功");
                secondMenu();

            }else{
                System.out.println("账号密码不匹配");
                firstMenu();
            }
    }
    public  void secondMenu(){
            System.out.println("1.查询所有员工信息");
            System.out.println("2.按工号查询员工信息");
            System.out.println("3.添加员工");
            System.out.println("4.修改员工工资");
            System.out.println("5.删除员工");
            System.out.println("6.退出");
            System.out.print("请选择：");
            switch (scan.next()){
                case "1":
                    fun.printAll();
                    reBack();
                    break;
                case "2":
                    System.out.println("请输入员工工号:");
                    eNo = scan.nextInt();
                    employee = fun.printByNo(eNo);
                    if (employee==null){
                        System.out.println("没有此工号信息!");
                    }else{
                        employee.print();
                    }
                    reBack();
                    break;
                case "3":
                    System.out.println("请输入员工工号:");
                    eNo = scan.nextInt();
                    System.out.println("请输入员工姓名:");
                    String name = scan.next();
                    System.out.println("请输入员工工资:");
                    money = scan.nextDouble();
                    int num = fun.addEmployee(new Employee(eNo,name,money));
                    if (num==2){
                        System.out.println("该员工工号已存在！添加失败");
                    }else if(num==0){
                        System.out.println("内存已满,添加失败");
                    }else{
                        System.out.println("添加成功");
                    }
                    reBack();
                    break;
                case "4":
                    System.out.println("请输入员工工号:");
                    eNo = scan.nextInt();
                    System.out.println("请输入新的工资:");
                    money = scan.nextDouble();
                    result = fun.updateMony(eNo,money);
                    if (result){
                        System.out.println("修改成功");
                    }else{
                        System.out.println("修改失败");
                    }
                    reBack();
                    break;
                case "5":
                    System.out.println("请输入员工工号:");
                    eNo = scan.nextInt();
                    result = fun.deleteEmployee(eNo);
                    if (result){
                        System.out.println("删除成功");
                    }else{
                        System.out.println("删除失败");
                    }
                    reBack();
                    break;
                case "6":
                    System.out.println("谢谢使用");
                    break;
                    default:
                        System.out.println("没有此选项");
                        secondMenu();
                        break;
            }
    }

    /**
     * 返回主菜单
     */
    private void reBack() {
        System.out.println("按0返回上级菜单");
        scan.next();
        secondMenu();
    }
}
